package p600;

import java.util.Arrays;

public class Leetcode_680 {
    public boolean validPalindrome(String s) {
        return valid(s, 0, s.length() - 1, false);
    }

    private boolean valid(String s, int i, int j, boolean used) {
        while (i < j) {
            char a = s.charAt(i), b = s.charAt(j);
            if (a != b) {
                if (used) {
                    return false;
                }
                return valid(s, i, j - 1, true) || valid(s, i + 1, j, true);
            }
            i++;
            j--;
        }
        return true;
    }
}
